<?php
/**
 * Description of fwiDB
 *
 * @author trunghpb
 */
class _fwiDB {
    private static $db;

    public static function createMySQL($dbdriver, $server, $user, $password, $database, $charset='utf8', $debug = true){
        if (_fwiDB::$db == null){             
            _fwiload::package('adodb5', 'adodb.inc');
            _fwiDB::$db = ADONewConnection($dbdriver);
            _fwiDB::$db->debug = $debug;

            $status = _fwiDB::$db->Connect($server, $user,
                    $password,$database);

            if (trim($charset) != '') {
                
                if (_fwiDB::$db->Execute("SET CHARACTER SET ".$charset) == false) {
                        throw new fwiException("[SET CHARACTER SET ".$charset."] is failed");
                }
                if (_fwiDB::$db->Execute("SET NAMES ".$charset) == false) {
                        throw new fwiException("[SET NAMES ".$charset."] is failed");
                }
            }

            if (!$status){
                throw new fwiException('Can not connect to DB');
            }
        }
        return _fwiDB::$db;
    }
}
?>
